package org.ricks.net.action.context.head;

import java.nio.ByteBuffer;

public class DefHeadMeta implements HeadMeta {
    private final short cmd;

    public DefHeadMeta(short cmd) {
        this.cmd = cmd;
    }

    @Override
    public int cmd() {
        return cmd;
    }

    @Override
    public ByteBuffer generateHeader(ByteBuffer buffer) {
        // 确保缓冲区有足够空间
        if (buffer.capacity() < 2) {
            buffer = ByteBuffer.allocate(2); // 如果传入缓冲区太小，创建新缓冲区
        }

        buffer.clear(); // 重置缓冲区
        buffer.putShort(cmd); // 写入命令号
        buffer.flip(); // 准备读取
        return buffer;
    }

    // 实现接口默认方法
    @Override
    public boolean isRpc() {
        return false; // 默认头部不是RPC
    }

    @Override
    public boolean isRpcResponse() {
        return false;
    }

    @Override
    public byte flags() {
        return 0; // 默认没有标志位
    }
}
